package com.zhiwen.controller;

import com.zhiwen.common.api.Result;
import com.zhiwen.domain.entity.Category;
import com.zhiwen.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 分类控制器
 */
@Tag(name = "分类管理", description = "问题分类相关接口")
@RestController
@RequestMapping("/categories")
@RequiredArgsConstructor
public class CategoryController {

    private final CategoryService categoryService;

    /**
     * 获取所有分类列表
     */
    @Operation(summary = "获取所有分类列表", description = "获取系统中所有分类")
    @ApiResponse(responseCode = "200", description = "获取成功",
                content = @Content(schema = @Schema(implementation = Category.class)))
    @GetMapping
    public Result<List<Category>> getAllCategories() {
        List<Category> categories = categoryService.list();
        return Result.success(categories);
    }

    /**
     * 获取所有可见的分类列表
     */
    @Operation(summary = "获取所有可见的分类列表", description = "获取系统中所有可见状态的分类")
    @ApiResponse(responseCode = "200", description = "获取成功",
                content = @Content(schema = @Schema(implementation = Category.class)))
    @GetMapping("/visible")
    public Result<List<Category>> getVisibleCategories() {
        List<Category> categories = categoryService.getAllVisibleCategories();
        return Result.success(categories);
    }
}
